name: Acceptance Tests
concurrency:
  group: acceptance-tests

on:
  workflow_dispatch:
  push:
    branches:
      - master
    paths-ignore:
    - 'README.md'
    - 'CHANGELOG.md'
    - 'LICENSE'
    - 'GNUmakefile'
    - 'website/**'
    - 'docs/**'
    - '.changelog/**'

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest

    env:
      CLOUDFLARE_ACCOUNT_ID: f037e56e89293a057740de681ac9abbe
      CLOUDFLARE_ALT_DOMAIN: terraform2.cfapi.net
      CLOUDFLARE_ALT_ZONE_ID: b72110c08e3382597095c29ba7e661ea
      CLOUDFLARE_DOMAIN: terraform.cfapi.net
      CLOUDFLARE_EMAIL: terraform-acceptance-test@cfapi.net
      CLOUDFLARE_ZONE_ID: 0da42c8d2132a9ddaf714f9e7c920711
      CLOUDFLARE_MUTUAL_TLS_CERTIFICATE: "-----BEGIN CERTIFICATE-----\\nMIIF+DCCA+CgAwIBAgIUWc0b+WiKSZob8wl2g/ujewoKCvgwDQYJKoZIhvcNAQEN\\nBQAwgZMxCzAJBgNVBAYTAlVTMQwwCgYDVQQIEwNOL0ExDDAKBgNVBAcTA04vQTEl\\nMCMGA1UEChMcVGVycmFmb3JtIEFjY2VwdGFuY2UgVGVzdGluZzEMMAoGA1UECxMD\\nTi9BMTMwMQYDVQQDEypUZXJyYWZvcm0gQWNjZXB0YW5jZSBUZXN0aW5nIENBIDE2\\nMTgyODU5MjYwHhcNMjEwNDEzMDM0ODAwWhcNMjYwNDEyMDM0ODAwWjCBkzELMAkG\\nA1UEBhMCVVMxDDAKBgNVBAgTA04vQTEMMAoGA1UEBxMDTi9BMSUwIwYDVQQKExxU\\nZXJyYWZvcm0gQWNjZXB0YW5jZSBUZXN0aW5nMQwwCgYDVQQLEwNOL0ExMzAxBgNV\\nBAMTKlRlcnJhZm9ybSBBY2NlcHRhbmNlIFRlc3RpbmcgQ0EgMTYxODI4NTkyNjCC\\nAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBANBzwmNB8g3eV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Nk1\\nkzhKrDk8fReEX+jmpG7n/q973nJ31KIBxk85owv/BFgnWpC7HPY+waIH0xNr2iZA\\nOu1orlBiBYAqG8zDBq3AGVlxg8yUOc5bik9OhCIwYyT2RFmd6z4O36uIM3LEzJ64\\nJj8TTjOP/ktqu+GZrUrnIjfu7mlGvc4u22P8ILJ2AZe5ITp/uhMRJbGbJGEMCCH3\\nkAKIEDATrevGdmgWUpdj8RNBS7+BK98eN+vcDqtY4Sudri2TwTkMbAscraacqrSJ\\n4rJfjSywVr4oWXyd2P83Hl398X3x04E0Rc15+wrGvaCSN5i1gzc30fTlz1X8dJQ3\\nccaHajJlRVZfuCrFBk6m5YRL7AoG4iFfoOuDZZJpjr9nXEzEONhRR5QAG83yMedS\\nd8//SuQhuJQTxJW7UzkWaao+32gW/RvuQun0XtCNoow/kMVMOeSjKL9xioM=\\n-----END CERTIFICATE-----"
      CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
      # CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
      # CLOUDFLARE_API_USER_SERVICE_KEY: ${{ secrets.CLOUDFLARE_API_USER_SERVICE_KEY }}
      CLOUDFLARE_LOGPUSH_OWNERSHIP_TOKEN: ${{ secrets.CLOUDFLARE_LOGPUSH_OWNERSHIP_TOKEN }}
      CLOUDFLARE_WORKSPACE_ONE_CLIENT_ID: d0ed71f01c884e8b94ec4e4d6639f609
      CLOUDFLARE_WORKSPACE_ONE_CLIENT_SECRET: ${{ secrets.CLOUDFLARE_WORKSPACE_ONE_CLIENT_SECRET }}
      CLOUDFLARE_WORKSPACE_ONE_API_URL: ${{ secrets.CLOUDFLARE_WORKSPACE_ONE_API_URL }}
      CLOUDFLARE_WORKSPACE_ONE_AUTH_URL: ${{ secrets.CLOUDFLARE_WORKSPACE_ONE_AUTH_URL }}
      CLOUDFLARE_PAGES_OWNER: jacobbednarz
      CLOUDFLARE_PAGES_REPO: pages-example
      CLOUDFLARE_R2_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
      CLOUDFLARE_R2_ACCESS_KEY_SECRET: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_SECRET }}

    steps:
    - name: Check out code into the Go module directory
      uses: actions/checkout@v4
    - name: Set up Go
      uses: actions/setup-go@v5
      with:
        go-version-file: 'go.mod'
      id: go
    - uses: actions/cache@v4
      with:
        path: ~/go/pkg/mod
        key: ${{ runner.os }}-go${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }}
    - name: Pre-Sweeper (SDKv2)
      run: go test ./internal/sdkv2provider -v -sweep="1" -timeout 60m
    - name: Pre-Sweeper (Framework)
      run: go test ./internal/framework/service/... -v -sweep="1" -timeout 60m
    - name: Run acceptance tests
      run: make testacc
    - name: Post-Sweeper (SDKv2)
      if: ${{ always() }}
      run: go test ./internal/sdkv2provider -v -sweep="1" -timeout 60m
    - name: Post-Sweeper (Framework)
      if: ${{ always() }}
      run: go test ./internal/framework/service/... -v -sweep="1" -timeout 60m
